//
//  AppCollectCell.m
//  MHO
//
//  Created by Hien NV on 7/11/14.
//  Copyright (c) 2014 maihoang. All rights reserved.
//

#import "AppCollectCell.h"

@implementation AppCollectCell

+ (instancetype)cellFromNib {
    return [[[NSBundle mainBundle] loadNibNamed:@"AppCollectCell" owner:self options:nil] objectAtIndex:0];
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    CGRect frame = self.rateView.frame;
    [self.rateView setFrame:CGRectMake(83, 20, frame.size.width, frame.size.height)];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

- (void)setFavorite:(BOOL)favorite {
    if (favorite) {
        [self.iconDownload setImage:[UIImage imageNamed:@"star_favorite.png"] forState:UIControlStateNormal];
    }
    else {
        [self.iconDownload setImage:[UIImage imageNamed:@"icon_download.png"] forState:UIControlStateNormal];
    }
}

- (IBAction)deleteGame:(id)sender {
    if (_delegate && [_delegate respondsToSelector:@selector(deleteGameId:)] && self.app) {
        [_delegate deleteGameId:self.app.appId];
    }
    else {
//        NSLog(@"delegate: %@ response: %d app: %@", [_delegate description], [_delegate respondsToSelector:@selector(deleteGameId:)])
        UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Thông báo" message:@"Có lỗi vừa xảy ra! Bạn vui lòng thử lại lúc khác!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    }
}
@end
